import React from 'react'
import { useLocation,useParams } from 'react-router-dom'
import qs from 'qs'

export default function News() {
const location = useLocation()
//location.state:0: {id: '001', news: '新闻1'}1: {id: '002', news: '新闻2'}2: {id: '003', news: '新闻3'}3: {id: '004', news: '新闻4'}
//location.search:?name%20=%20%E5%BC%A0%E4%B8%89%20&%20id%20=%20002"
//useParams():{id: '001'}
// console.log(location);
// console.log(useParams());
const state = location.state
const {name,id} = qs.parse(location.search.split('?')[1])
// const newsType = useParams().id
  return (
    <div>
      <p>姓名是{name},编号是{id}</p>
      <p>当前新闻版块{useParams().id}</p>
      <ul>
        {
          state.map(item=>{
            return <li key={item.id}>{item.name}</li>
          })
        }
      </ul>
    </div>
  )
}
